package src.com.zuiacsn;

import src.com.test.Student;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/*
* 获取类的成员方法(和之前的两个相同)
* */
public class Demo4 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Class<Student> studentClass = Student.class;

        Method setAge = studentClass.getMethod("setAge");
        System.out.println(setAge.getName()+" "+
                setAge.getParameterCount()+""+
                setAge.getReturnType());

        /*
        * public Object invoke(Object obj,Object.....args) 触发某个对象的方法执行
        * */
        setAge.setAccessible(true);
        Student stu = new Student("张三",23);
        setAge.invoke(stu);
    }
}
